package constant;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;

/**
 * 配置文件读取
 * USER: lintc 【lintiancong@zhuojianchina.com】
 * DATE: 2017-01-18 16:04
 */
public class ConstantUtil {

    private static ResourceBundle resourceBundle = ResourceBundle.getBundle("mongo", Locale.getDefault());

    /**
     * 读取静态数据
     * @param name
     * @return
     */
    public static String proper(String name) {
        Properties prop = new Properties();
        InputStream in;
        String url = null;
        try {
            in = ConstantUtil.class.getClassLoader().getResourceAsStream("/configure.properties");
            BufferedReader bf = new BufferedReader(new InputStreamReader(in, "UTF-8"));
            prop.load(bf);
            url = prop.getProperty(name);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return url;
    }

    /**
     * 读取配置信息
     * @param name
     * @return
     */
    public static String getPro(String name) {
        return resourceBundle.getString(name);
    }

    public static void main(String[] args) {
        System.out.println(getPro("port"));
    }
}
